
#include <iostream>
#include <future>

int Add(int x, int y)
{
    std::cout << "into Add" << std::endl;
    return x + y;
}

int main()
{
    //进行异步非阻塞调用. 异步先调用Add函数再返回结果.
    //std::future<int> res = std::async(std::launch::async, Add, 11, 22);
    //同步的话就是先休眠再调用Add再返回结果.
    std::future<int> res = std::async(std::launch::deferred, Add, 11, 22);

    //休眠一秒.
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout << "-------------------" << std::endl;
    std::cout <<  res.get() << std::endl;  //获取异步结果.
    return 0;
}